import sys,math
from PyQt5.QtWidgets import *
from PyQt5.QtGui import *
from PyQt5.QtCore import *

class Drawing(QWidget):
    def __init__(self,parent=None):
        super(Drawing,self).__init__(parent)
        self.setWindowTitle("绘图")
        self.resize(300,300)

    def paintEvent(self, event):
        qp=QPainter(self)
        qp.begin(self)
        #自定义绘图方法
        self.drawPoints(qp)
        qp.end()
    def drawPoints(self,qp):
        qp.setPen(Qt.blue)
        size=self.size()
        for i in range(900):
            x=100*(-1+2.0*i/900)+size.width()/2.0
            y=30*math.sin((x-size.width()/2.0)*math.pi/30)+size.height()/2.0
            qp.drawPoint(x,y)

if __name__ == '__main__':
    app=QApplication(sys.argv)
    demo=Drawing()
    demo.show()
    sys.exit(app.exec_())